package com.fimmlps.reronge.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fimmlps.reronge.entity.EntryUserSubscribe;
import com.fimmlps.reronge.mapper.EntryUserSubscribeMapper;
import com.fimmlps.reronge.service.IEntryUserSubscribeService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

@Service
public class EntryUserSubscribeServiceImpl extends ServiceImpl<EntryUserSubscribeMapper, EntryUserSubscribe> implements IEntryUserSubscribeService {
    @Override
    public boolean isFriend(int userID1, int userID2) {
        EntryUserSubscribe subscribe = baseMapper.selectOne(new QueryWrapper<EntryUserSubscribe>().eq("user_id",userID1).eq("subed_user_id",userID2));
        if(subscribe!=null)
            return true;
        subscribe = baseMapper.selectOne(new QueryWrapper<EntryUserSubscribe>().eq("user_id",userID2).eq("subed_user_id",userID1));
        if(subscribe!=null)
            return true;
        return false;
    }

    @Override
    public EntryUserSubscribe getByIDs(int userID1, int userID2) {
        EntryUserSubscribe subscribe = baseMapper.selectOne(new QueryWrapper<EntryUserSubscribe>().eq("user_id",userID1).eq("subed_user_id",userID2));
        if(subscribe!=null)
            return subscribe;
        subscribe = baseMapper.selectOne(new QueryWrapper<EntryUserSubscribe>().eq("user_id",userID2).eq("subed_user_id",userID1));
        return subscribe;
    }

    @Override
    public ArrayList<EntryUserSubscribe> getAllFriends(int userId) {
        List<EntryUserSubscribe> subscribes = baseMapper.selectList(new QueryWrapper<EntryUserSubscribe>().eq("user_id",userId).or().eq("subed_user_id",userId));
        return new ArrayList<>(subscribes);
    }
}
